package com.ubtechinc.cruzr.launcher2;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import com.ubtechinc.cruzr.launcher2.adapter.SettingAdapter;
import com.ubtechinc.cruzr.launcher2.model.entity.AppInfo;
import com.ubtechinc.cruzr.launcher2.presenter.SettingPresenter;
import com.ubtechinc.cruzr.launcher2.view.SettingView;

import java.util.List;

public class LauncherSettingActivity extends Activity implements SettingView {
    private SettingAdapter mAdapter;
    private SettingPresenter mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        mPresenter = new SettingPresenter(this);
        initView();
//        List<AppInfo> list  = FilterDao.get().getAllAppInfo();
//        for(AppInfo info : list){
//            LogUtils.e("当前数据库还有的数据 " + info.id + " " + info.activityname);
//        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.unBindView();
    }

    private void initView() {
        RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.id_recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new SettingAdapter(this, mPresenter.getData());
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setonLastItemCallback(new SettingAdapter.onLastItemCallback() {
            @Override
            public void onLastItem() {
                Toast.makeText(LauncherSettingActivity.this, R.string.last_item_remind, Toast.LENGTH_SHORT).show();
            }
        });

    }

    @Override
    public void onAllApppdate(List<AppInfo> list) {
        if (mAdapter != null) {
            mAdapter.updateData(list);
        }
    }

    public void onclick(View v) {
        finish();
    }
}
